<div class="widget">
	<div class="widget-header bg-blue">
		<i class="widget-icon icon-notebook"></i> 
		<span class="widget-caption"> 机构注册 </span>
		<div class="widget-buttons">
			<a href="javascript:void(0);" onclick="handlerCancel(this);" title="关闭"
				 data-toggle="dispose" data-refresh-table="#table-center"> <i class="fa fa-times"></i> </a> 
		</div>
	</div>
	<div class="widget-body">
		<!-- TODO 基本信息 -->
		<div class="widget radius-bordered">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> 基本信息 </span>
			</div>
			<div class="widget-body editor-body-sm editor-body-center">
				
			</div>
		</div>
		
		<!-- TODO 校区信息 -->
		<div class="widget radius-bordered" id="editor-panel-region">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> 校区信息 </span>
				<div class="widget-buttons buttons-bordered">
					<button class="btn btn-default btn-sm" title="添加" 
									data-toggle="tooltip" data-placement="top" 
									data-tool="append" 
									data-template-id="#form-region-template" 
									data-template-path="/miwawa/content/system/center/template.html" 
									data-template-target=".editor-body-region"
									data-loaded="onRegionEditorLoaded">
						<i class="fa fa-plus"></i>
					</button>
					<button class="btn btn-default btn-sm" title="删除" 
									data-toggle="tooltip" data-placement="top" 
									data-tool="remove" data-template-target=".editor-body-region">
						<i class="fa fa-minus"></i>
					</button>
				</div>
			</div>
			<div class="widget-body editor-body-sm editor-body-region">
				
			</div>
		</div>
	</div>
</div>

<!-- 提交表单 ========================================================= -->
<form id="editor-form-center" action="/miwawa/default/common/update" method="post" 
			name="com.app.miwawa.api.system.entity.Center">
			<input type="hidden" name="bean['status']" value="0">
			<input type="hidden" name="bean['invalid']" value="F">
</form>
<form id="editor-form-region" action="/miwawa/default/common/update" method="post" 
			name="com.app.miwawa.api.system.entity.Region"
			data-foreign-src="#editor-form-center" 
			data-foreign-key="com.app.miwawa.api.system.entity.Center">
			<input type="hidden" name="bean['status']" value="0">
			<input type="hidden" name="bean['invalid']" value="F">
			<input type="hidden" name="bean['centerid']" id="centerid">
</form>

<!-- 查询表单 ========================================================= -->
<form id="search-form-region" action="/miwawa/default/common/search.json" method="post" 
			name="com.app.miwawa.api.system.entity.Region" 
			data-template-target=".editor-body-region" data-template-id="#view-region-template" 
			data-template-path="/miwawa/content/system/center/template.html">
			<input type="hidden" name="status" value="0" data-search-group="and" data-search-operation="EQ">
			<input type="hidden" name="invalid" value="F" data-search-group="and" data-search-operation="EQ">
			<input type="hidden" name="centerid" value="0" data-search-group="and" data-search-operation="EQ">
</form>
    
<script type="text/javascript">
	require(['domReady'],function(domReady){
		domReady(function () {
			loadData();
    });
	});
	
	var center;
	function loadData(){
		center = jQuery("#table-center").data("selectedRow");
		jQuery(":hidden[name='centerid'], #centerid").val(center.id);
		
		jQuery(".editor-body-center").loadform("load", {
			templateId: "#view-center-template",
			templatePath: "/miwawa/content/system/center/template.html",
			templateData: center,
			templateHelper: {
				"chosen":function(value){
					require(['jquery.plugin.form'], function(form){
						form.chosen("#type").select("#type",{
							url: "/miwawa/default/common/select.json",
							querys: {"pcode_EQ": "c_organ_type"}
						},function(chosen){
							jQuery("option[value='"+value+"']",chosen).attr("selected","selected").trigger('chosen:updated');
						});
					});
				}
			},
			onLoadSuccess: function(){
				require(['jquery.plugin.form', 'jquery.bootstrap.editable'],function(form, editable){
					form.datepicker('.date-selector');
					form.tooltip("[data-toggle='tooltip']");
					editable.register("[data-editable]");
				});
			}
		});
			
		jQuery("#search-form-region").loadform("many",{
			"region":function(value){
				require(['jquery.plugin.form'],function(form){
					form.chosen(jQuery('#prov,#pref,#county',".form-viewer-region"));
					form.region(jQuery("#county",".form-viewer-region"),{"pid":"310100"},function(chosen){
						jQuery("option[value='"+value+"']",chosen).attr("selected","selected").trigger('chosen:updated');
					});
				});
			}
		});
	}
	
	function onRegionEditorLoaded(){
		require(['jquery.plugin.form'],function(form){
			form.chosen(jQuery('#prov,#pref,#county',".form-editor-region"));
			form.region(jQuery("#county",".form-editor-region"),{"pid":"310100"});
			form.tooltip("[data-toggle='tooltip']");
		});
	}
	
	function updateAdmin(){
		jQuery.ajaxsend({
			url:"/miwawa/default/common/update",
			data:{
		       	"entityClass" : "com.app.miwawa.api.system.entity.Admin",
		       	"bean":{
		       		"id":center.id,
		       		"center":jQuery("#name",".form-editor-center").val()
		       	}
		  }
		})
	}
</script>